import { request } from './utils'
import { generateRandomString } from '@/api/utils'
//获取登录二维码
export const getSrc = (data) => {
 return request({
  url: '/wx/login',
  method: 'get',
  params: data
 })
}

//轮询查看是否登录成功
export const getLogin = (data) => {
 return request({
  url: '/wx/getToken',
  method: 'get',
  params: data
 })
}

//获取所有用户
export const getUser = (pageNum, pageSize) => {
 const token = JSON.parse(localStorage.getItem('token')).accessToken
 let data = {
  pageNum,
  pageSize
 }
 let headers = {
  token: token
 }
 return request({
  url: '/users/getUser',
  params: data,
  headers
 })
}

//获取新的token
export const getNewToken = () => {
 const token = JSON.parse(localStorage.getItem('token')).refreshToken
 let headers = {
  token: token
 }
 const data = {
  time: new Date().getTime(),
  data: [],
  key: generateRandomString()
 }
 return request({
  url: '/wx/refreshToken',
  headers,
  params: data
 })
}

export const test = () => {
 let data = {
  red: '123'
 }
 return request({
  url: '/users/test',
  method: 'POST',
  data: data
 })
}
